package com.ms.oschina.task;

import com.ms.oschina.api.remote.OkHttpClientManager;
import com.ms.oschina.api.remote.OkHttpClientManager.OnGetNetResultListener;
import com.ms.oschina.base.BaseAsyncTask;
import com.ms.oschina.bean.HttpResponse;
import com.ms.oschina.util.XmlUtils;

public class NetXMLParseTask<T> extends BaseAsyncTask<T> {

	private int requestCode;
	private String path;
	private OnGetNetResultListener<T> listener;
	private Class<T> clazz;

	public NetXMLParseTask(String path, int requestCode, Class<T> clazz,
			OnGetNetResultListener<T> listener) {
		this.path = path;
		this.requestCode = requestCode;
		this.clazz = clazz;
		this.listener = listener;
	}

	@Override
	protected T exeCute() throws Exception {
		String string = OkHttpClientManager.getInstance()
				.getSyncAsString(path);
		// 解析内容
		return XmlUtils.toBean(clazz, string.getBytes());
	}

	@Override
	protected void onPostExe(HttpResponse<T> result) {
		listener.onGetNetResult(requestCode, result);
	}
	
}